<script setup >
import { ref, onMounted, computed } from 'vue'
import { useRoute } from 'vue-router'
import { getHotGoodsApI } from '@/apis/detail'
let route = useRoute()
let props = defineProps({
  hot_type: {
    typeof: String,
    default: () => {
      return 'hot'
    }
  }
  
})
const TYPEMAP = {
  1: '月热门',
  2: '周热门'
}

// 根据请求的数据不同，所以对应的内容也是不同的。
const title = computed(() => {
  return TYPEMAP[props.hot_type]
})

const goodsList = ref([])
let getHotGoods = async () => {
  const res = await getHotGoodsApI({ id: route.params.id, type: props.type })
  goodsList.value = res.result
}

onMounted(() => {
  // 请求热门商品数据
  getHotGoods()
})
</script>
<template>
  <div class="goods-hot">
    <h3>{{title}}</h3>
    <!-- 商品区块 -->
    <RouterLink to="/" class="goods-item" v-for="item in goodsList" :key="item.id">
      <img :src="item.picture" :alt="item.name">
      <p class="name ellipsis">{{item.name}} </p>
      <p class="desc ellipsis">{{item.desc}}</p>
      <p class="price">&yen;{{item.price}} </p>
      <p class="desc">成交量：{{item.orderNum}} </p>
    </RouterLink>
  </div>
</template>

<style scoped lang="scss">
.goods-hot {
  h3 {
    height: 70px;
    background: $helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }

  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;

    img {
      width: 160px;
      height: 160px;
    }

    p {
      padding-top: 10px;
    }

    .name {
      font-size: 16px;
    }

    .desc {
      color: #999;
      height: 29px;
    }

    .price {
      color: $priceColor;
      font-size: 20px;
    }
  }
}
</style>
